package org.swingfly.works.jutils;

import java.lang.reflect.Proxy;

/**
 * null safe string utils
 */
public class StringUtils {
    /**
     * if the string is null , ""  or blank
     * @param str
     * @return  true,if the string is null , "" or blank
     */
    public static boolean isEmpty(String str) {
        return str == null || "".equals(str.trim());
    }

    /**
     * @param strings null will be ignored
     * @return if strings is null,return null;
     */
    public static String concat(String... strings) {

        if (strings == null) return null;

        if (strings.length == 0) return "";

        if (strings.length == 1) return strings[0];

        int length = 0;
        for (String string : strings) {
            if (!isEmpty(string))
                length += string.length();
        }

        StringBuilder builder = new StringBuilder(length);
        for (String string : strings) {
            if (!isEmpty(string))
                builder.append(string);
        }

        return builder.toString();
    }

    public static boolean contains(String first, String second) {
        if (first == null || second == null)
            return false;
        else
            return first.contains(second);
    }

    /**
     * if the first string equals the second.
     * @param first
     * @param second
     * @return true,only if both first and second is not null and first.equals(second);
     */
    public static boolean equals(String first, String second) {
        if (first == null || second == null)
            return false;
        else
            return first.equals(second);

    }



}
